import datetime
import time
import numpy as np
import pandas as pd
from keras.models import load_model
import keras.backend.tensorflow_backend as tb

import random


def randomChange(num_list):
    res = []
    for i in num_list:
        res.append(i * random.randint(95, 105) / 100)
    return res


def predict_boxoffice():
    tb._SYMBOLIC_SCOPE.value = True
    global model
    model = load_model('model/boxoffice.h5')
    from dateutil import relativedelta
    current = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y-%m")
    current += '-01 00:00:00'
    pre = []
    for i in range(1, 4):
        pre.append(time.mktime((datetime.datetime.strptime(current,
                                                           '%Y-%m-%d %H:%M:%S') + relativedelta.relativedelta(
            months=i)).timetuple()))

    res = model.predict(pd.Series(pre)[:, np.newaxis, np.newaxis]) * 38727399.16986828
    return randomChange([i[0] for i in res.tolist()])
